package com.gluxen.test;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.poi.ss.formula.functions.T;

import com.gluxen.common.constant.SystemConstant;
import com.gluxen.controller.WeixinController;
import com.gluxen.po.AccessToken;
import com.gluxen.po.AutoReply;
import com.gluxen.po.AutoReplyMessage;
import com.gluxen.po.AutoReplyMessage_news;
import com.gluxen.po.AutoReply_KeyWord;
import com.gluxen.po.AutoReply_Rule;
import com.gluxen.po.AutoReply_list;
import com.gluxen.po.AutoReply_new;
import com.gluxen.po.Autoreply_keyword_info;
import com.gluxen.util.DateUtil;
import com.gluxen.util.JsonUtils;
import com.gluxen.util.MessageUtil;
import com.gluxen.util.weixinUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class weixintest {
	public static String dateToStrLong(java.util.Date dateDate) {  
	    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");  
	    String dateString = formatter.format(dateDate);  
	    return dateString;  
	}

	public static void main(String[] args) throws IOException{
		String  filePath="D://projects//Git//ABCWeixin//WebContent//image//app.jpg";
		//D://projects//Git//ABCWeixin//WebContent//image//app.jpg
		AccessToken token = weixinUtil.getAccessToken();
		
		
		/*将图片上传到微信服务器并取得 MediaId*/
		//String path="D:/fire.jpg";
		//String mediaID = weixinUtil.upload2(filePath, token.getToken(), "image");
		//System.out.println(mediaID);
		
		
		/*创建自定义菜单*/
		int result = weixinUtil.createMenu(token.getToken(), MessageUtil.initMenu());
		System.out.println(result);
		/**
		 * 上传永久素材（图片）
		 */
//		String upload=weixinUtil.upload(filePath, token.getToken(), "image");
//		System.out.println(upload);
		//System.out.println(result);
		/*取得当前日期*/
		//String str = DateUtil.dateToString(new Date(),"yyyy-MM-dd");
		//String str = d1.format(new Date());//取得当前日期
		
		
		
		//测试获取自动回复规则
		/*String autoReplyStr = weixinUtil.Get_autoReply_json();
		JSONObject obj=JSONObject.fromObject(autoReplyStr);
		Map<String,Class<?>> map = new HashMap<String,Class<?>>();
		//子类可以代替父类,可以转化为一个对象前提是字符串中的值都能在对象中找到对应的位置，对象中位置比较多的情况下也能成功。
		map.put("list", AutoReply_new.class);
		map.put("keyword_list_info", AutoReply_KeyWord.class);
		map.put("reply_list_info", AutoReplyMessage_news.class);
		//将规则封装为一个实体类。
		AutoReply autoReply = (AutoReply)JSONObject.toBean(obj,AutoReply.class,map);//指定转换的类型，但仍需要强制转化-成功
		
		System.out.println(autoReply.getIs_autoreply_open());*/
		
		/*AutoReply autoReply1 = WeixinController.autoReply;
		//AutoReplyMessage_news message = (AutoReplyMessage_news)autoReply.getKeyword_autoreply_info().getList().get(3).getReply_list_info().get(0);
		String strii=autoReply1.getKeyword_autoreply_info().getList().get(3).getKeyword_list_info().get(0).getContent();
		//System.out.println(message.getNews_info().getList().get(0).getCover_url());
		System.out.println(strii);*/
		
		
		//测试根据关键字获取自动回复消息的返回结果是否正确。正确！
		//String reply = weixinUtil.get_autoreply_message("到这儿","这儿来","你好");
		//System.out.println(reply);
		
		
		
//		String str = DateUtil.dateToString(new Date(),"yyyy-MM-dd");
//		Date date = DateUtil.stringToDate(str,SystemConstant.DATE_PATTEN);
//		System.out.println(str+"--"+date);
//		System.out.println(str+"--"+DateUtil.formatDate(date, SystemConstant.DATE_PATTEN));
		
		
//		String url = "http://freegeoip.net/json/50.78.253.58";
//		JSONObject jsonObject = weixinUtil.doGetStr(url);
//		String country = jsonObject.getString("country_code");
//		System.out.println(country);
	}
}
